//
//  ClassNameViewController.m
//  jiyujiaProgram
//
//  Created by 中良 赵 on 15/12/4.
//  Copyright © 2015年 中良 赵. All rights reserved.
//

#import "ClassNameViewController.h"


@interface ClassNameViewController ()
{
    NSArray*fristArr;
    NSArray*secondArr;
    int SelectTag;
    NSString *firstString;
    int JB;
    NSString *PARENT_ID;

}
@end

@implementation ClassNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    SelectTag=0;
//    fristArr=[[NSArray alloc]initWithObjects:@"N1",@"N2",@"N3",@"N4",@"N5", nil];
//    secondArr=[[NSArray alloc]initWithObjects:@" 保过班",@"动漫日语",@"商务日语", nil];
    JB=2;
    PARENT_ID=@"e8499c91a8fb404695f6e37256cb80ce";
    [self getDicList:JB parent_id:PARENT_ID];
     firstString=@"";
}

-(void)getDicList:(int)jd parent_id:(NSString*)ID{
//    UserInfoManager *userInfo = [UserInfoManager sharedUserInfoManager];
    [[HttpManager defaultManager] getRequestToUrl:[NSString stringWithFormat:@"%@?JB=%d&PARENT_ID=%@",RequestURL(QUERYDICTIONARIESLIST),jd,ID]params:nil complete:^(BOOL successed, NSDictionary *result) {
        if (successed) {
            NSLog(@"%@",result);
            fristArr=[result objectForKey:@"data"];
            if (![fristArr isEqual:[NSNull null]]) {
                JB++;
                [_tableview reloadData];
            }else{
                NSDictionary *dict =[[NSDictionary alloc] initWithObjectsAndKeys:[firstString substringFromIndex:1],@"classname", nil];
                //创建通知
                NSNotification *notification =[NSNotification notificationWithName:@"postStringToUp" object:nil userInfo:dict];
                //通过通知中心发送通知
                [[NSNotificationCenter defaultCenter] postNotification:notification];
                [self.navigationController popViewControllerAnimated:YES];
            }
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return fristArr.count;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.row==2) {
//        return 120.f;
//    }
    return 66.f;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    firstString=[NSString stringWithFormat:@"%@/%@",firstString,[[fristArr objectAtIndex:indexPath.row] objectForKey:@"name"]];
//    firstString=[[fristArr objectAtIndex:indexPath.row] objectForKey:@"name"];
    [self getDicList:JB parent_id:[[fristArr objectAtIndex:indexPath.row] objectForKey:@"zd_ID"]]
    ;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            cell.textLabel.textAlignment=NSTextAlignmentCenter;
        }
    if (fristArr.count) {
        cell.textLabel.text=[[fristArr objectAtIndex:indexPath.row] objectForKey:@"name"];
    }

//    if (cell == nil) {
//        cell=[[[NSBundle mainBundle] loadNibNamed:@"YueKeTableViewCell" owner:self options:nil] objectAtIndex:0];
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    }
//    switch (indexPath.row) {
//        case 0:
//        {
//            cell.textLabel.text=@"课程名称";
//        }
//            break;
//        case 1:
//        {
//            cell.lblClassTitle.text=@"课程费用";            
//        }
//            break;
//        case 2:
//        {
//            cell.lblClassTitle.text=@"课程备注";
//            cell.lblClassText.text=@"(已便授课老师更了解你的情况)";
//            cell.lblClassText.textColor=[UIColor lightGrayColor];
//            [cell.lblClassText setFont:[UIFont fontWithName:SystemFont size:12.f]];
//            cell.imgTap.hidden=YES;
//            
//            cell.lblClassText.textAlignment=NSTextAlignmentLeft;
//            PlaceholderTextView *tv=[[PlaceholderTextView alloc]init];
//            [tv setFrame:CGRectMake(cell.lblClassTitle.frame.origin.x, cell.lblClassTitle.frame.origin.y+CGRectGetHeight(cell.lblClassTitle.frame)+10, cell.contentView.frame.size.width-20, 40.f)];
//            [cell.contentView addSubview:tv];
//            tv.placeholder=@"请输入备注";
//        }
//            break;
//        case 3:
//        {
//            cell.lblClassTitle.text=@"上课时间";
//            cell.lblClassText.text=@"";
//        }
//            break;
//        case 4:
//        {
//            cell.lblClassTitle.text=@"上课方式";
//            cell.lblClassText.text=@"";
//        }
//            break;
//            
//        default:
//            break;
//    }
    return cell;
}
- (IBAction)backAction:(id)sender {
    if (SelectTag==1) {
        SelectTag=0;
        [_tableview reloadData];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
